package jdbc;

import java.sql.Connection;
import java.sql.Statement;
import java.util.Scanner;
public class RegDeno {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入用户名：");
        String username = sc.next();
        System.out.println("请输入密码：");
        String password = sc.next();
        System.out.println("请输入昵称：");
        String nickname = sc.next();
        System.out.println("请输入年龄：");
        int age = sc.nextInt();
        try (Connection conn = DBUtil.getConnection();) {
            Statement statement = conn.createStatement();
            String sql = "INSERT INTO user(username,password,nickname,age)" +
                    "VALUES ('"+username+"','"+password +"','"+ nickname +"',"+ age+" )";
            int rows = statement.executeUpdate(sql);
            System.out.println(rows>0?"注册成功！":"注册失败！");
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
}
